package cn.micai.base.executor;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Auther: zhaoxinguo
 * @Date: 2018/7/17 10:58
 * @Description: 创建一个可变的定长的线程池，使用受限队列和“调用者运行”饱和策略
 */
public class ExecutorExample1 {

    private static final int N_THREADS = 4;
    private static final int CAPACITY = 3000;

    static ThreadPoolExecutor executor;

    static {
        executor = new ThreadPoolExecutor(N_THREADS, N_THREADS,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(CAPACITY));
        // “调用者运行”饱和策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    }

}
